package com.hualan.zhsq.controller.information;



import com.hualan.zhsq.entity.information.StorageRoom;
import com.hualan.zhsq.service.information.StorageRoomService;
import com.hualan.zhsq.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/storageRoom")
public class StorageRoomController {

    @Autowired
    private StorageRoomService storageRoomService;


    /**
     * 新增储物室
     * @param storageRoom
     * @return
     */
    @RequestMapping("/add")
    public Result add(@RequestBody StorageRoom storageRoom){
        int rows = storageRoomService.add(storageRoom);
        return rows>0?Result.success():Result.error();
    }


    /**
     * 修改储物室信息
     * @param storageRoom
     * @return
     */
    @RequestMapping("/edit")
    public Result edit(@RequestBody StorageRoom storageRoom){
        int rows = storageRoomService.edit(storageRoom);
        return rows>0?Result.success():Result.error();
    }

    /**
     * 根据id删除储物室
     * @param id
     * @return
     */
    @RequestMapping("/remove")
    public Result remove(Integer id){
        int rows = storageRoomService.remove(id);
        return rows>0?Result.success():Result.error();
    }

    /**
     * 批量删除储物室
     * @param ids
     * @return
     */
    @RequestMapping("/removeBatch")
    public Result removeBatch(Integer[] ids){
        int rows = storageRoomService.removeBatch(ids);
        return rows>0?Result.success():Result.error();
    }

    /**
     * 根据id查找
     * @param id
     * @return
     */

    @RequestMapping("/findById")
    public Result<StorageRoom> findById(Integer id){
        return Result.success(storageRoomService.findById(id));
    }

    /**
     * 查找全部
     * @return
     */
    @RequestMapping("/find")
    public Result<List<StorageRoom>> find(){
        return Result.success(storageRoomService.find());
    }

    /**
     * 分页查找
     * @param pageNum
     * @param pageSize
     * @param storageRoom
     * @return
     */
    @RequestMapping("/findPage")
    public Result<Map<String,Object>> findPage(Integer pageNum, Integer pageSize, StorageRoom storageRoom){
        return Result.success(storageRoomService.findPage(pageNum, pageSize, storageRoom));
    }

}
